<%--
 *  File:    CityCodeEdit.jsp
 *  @Author: StephenLiu
 *  Date:    Tuesday, July 15, 2003

 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ include file="/inc/SessionTimeout.inc" %>

<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  Category cat = Category.getInstance("jsp.CityCodeEdit");
  String strModuleName = "OGM";
  String privilegeCode = "Z0814";
  String strTableName = "ovcity";
%>

<%@ include file="/inc/PageDefault.inc"%>
<%@ include file="/inc/Security.inc"%>
<%@ include file="/inc/FrmDefault.inc"%>
<%@ include file="/inc/LocationDefault.inc"%>

<html>
<head>
<title>citycodeedit</title>
<PageFlow:CheckPageFlow pageName="cityedit"/>
<%@include file="/inc/InitEdit.inc"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<script language="JavaScript">
function page_save() {
	if (document.frm.istarget1.checked==true){
		document.frm.istarget.value='Y';
	}
	else{
		document.frm.istarget.value='N';
	}
    //alert(document.frm.istarget.value);
  if(!checkForm(frm)) return;
  if ("<custom:write name="cityinfo" property="cityid"/>" == "")
    MLCSTransform(frm);
  if (document.frm.citycode.value == document.frm.parentcitycode.value){
    alert('<%=message.getMessageDesc("CAN_NOT_BE_PARENTCITY_OF_ONESELF")%>');
    return;
  }
  //var theresponsecode = frm.responsecode.value;
  //if (theresponsecode == "" || theresponsecode == -1) {
    //alert("<%= message.getMessageDesc("Can_not_be_null", label.getLabelName("L_CostCenterCode"))%>");
    //return;
  //}
  
  frm.numrows.value = Number(<%= ConstantProp.multiLangNumber %>);
  //alert(document.frm.istarget.value);
  frm.actionname.value = "save";
  frm.target = "_self";
  isRunning = true;
  frm.submit();
}
function page_selectRegion() {
  var thecountry = frm.countrycode.value;
  if(thecountry == "" || thecountry == -1) {
    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST", label.getLabelName("L_CountryName"))%>");
    return;
  }
  if(popwindow != null)
    popwindow.close();
  popwindow = window.open('../masterdata/ogm/RegionSelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=' + thecountry, 'newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
}
function page_setRegion(code, name) {
  if(code != document.frm.regioncode.value) {
    document.frm.regioncode.value = " ";
    document.frm.regionname.value = " ";
  }
  document.frm.regioncode.value = code;
  document.frm.regionname.value = name;
  if (popwindow != null)
    popwindow.close();
}
function selectChange() {
  frm.regioncode.value = "";
  frm.regionname.value = "";
}
function getRegion() {
  var theregion = frm.regioncode.value;
  if (theregion == "" || theregion == -1) {
    alert("<%= message.getMessageDesc("Can_not_be_null", label.getLabelName("L_RegionName"))%>");
    return;
  }
  frm.cityname.value = frm.cityname0.value;
  frm.actionname.value = "selectregion";
  frm.target = "_self";
  isRunning = true;
  frm.submit();
}
<%--add by garygu--%>
function page_selectParentCity()
{
  var thecity = frm.citycode.value;	
  var thecountry = frm.countrycode.value;
  if(thecountry == "" || thecountry == -1) {
    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST", label.getLabelName("L_CountryName"))%>");
    return;
  }
  var theregion = frm.regioncode.value;
  if(theregion == "" || theregion == -1) {
    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST", label.getLabelName("L_RegionName"))%>");
    return;
  }
  if(popwindow != null)
    popwindow.close();
  popwindow = window.open('../masterdata/ogm/CitySelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=' + thecountry + '&owncitycode='+thecity+'&regioncode=' + theregion, 'newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
}
function page_setCity(code,name,id)
{
  document.frm.parentcityid.value = id;
  document.frm.parentcitycode.value = code;
  document.frm.parentcityname.value = name;
  if (popwindow != null)
    popwindow.close();
}
function getParentCity() {
  var theparentcity = frm.parentcitycode.value;
  if (theparentcity == "" || theparentcity == -1) {
<%--    alert("<%= message.getMessageDesc("Can_not_be_null", label.getLabelName("L_ParentCity"))%>");--%>
   document.frm.parentcityname.value ="";
   return;
  }
  else{
  frm.cityname.value = frm.cityname0.value;
  frm.actionname.value = "selectparentcity";
  frm.target = "_self";
  isRunning = true;
  frm.submit();
  }
}


function page_selectCostCenter()
{
  if(popwindow != null)
    popwindow.close();
 // popwindow = window.open('SelectCostCenter.jsp?<%= OvalTools.randomURL() %>, 'newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
 popwindow = window.open('SelectCostCenter.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>', 'newwindow', 'height=500, width=700,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
}

function page_setCostCenter(id,code,name)
{
  document.frm.responsecenterid.value = id;
  document.frm.responsecode.value = code;
  document.frm.responsename.value = name;
  if (popwindow != null)
    popwindow.close();
}

function onLoad(){

	<%
	String istarget1 = "";
	String isdisable ="";
	isdisable=(String)pageContext.getAttribute("isdisable");
	HashMap cityinfo=(HashMap)pageContext.getAttribute("cityinfo");
	if(cityinfo != null){
	istarget1=(String)cityinfo.get("istarget");
	%>
	<%//System.out.print(istarget1+"123");%>
	<%
	if(istarget1=="" || istarget1==null){
		istarget1 = "1";
	}else{
		if(istarget1.equals("Y")){
		  istarget1="2";
		}
	}
	%>
	<%if(istarget1.equals("2")){%>
	 document.frm.istarget1.checked=true;
	<%}else if(istarget1.equals("1")){%>
	 document.frm.istarget1.checked=false;
	<%}%>
	
	<%
	if(!isdisable.equals("Y")){
	%>
	//alert(1);
	document.frm.istarget1.disabled=true;
	<%}}%>
	
}
<%--add by garygu--%>
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="onLoad();">
<form name="frm" method="post" action="../Dispatcher">
  <input type="hidden" name="pagename" value="cityedit">
  <input type="hidden" name="actionname">
  <custom:hidden name="cityinfo" property="cityid"/>
  <custom:hidden name="cityinfo" property = "istarget"/>
  <custom:hidden property="numrows"/>
  <custom:hidden property="isdisable"/>
<%@include file="/inc/PageLocation.inc" %>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="summary_top"></td>
  </tr>
  <tr>
    <td>
      <table border=0 cellpadding=0 cellspacing=0 width="100%">
        <tr>
          <td valign=top>
            <table border=0 cellpadding=1 cellspacing=0 width="100%">
              <tbody>
              <tr>
                <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 1px">
                  <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
                    <tr>
                      <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px">
                        <div id=div1 style="HEIGHT: 340px; OVERFLOW: auto">
                          <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="1">
                            <tr>
                              <td colspan="4" class="td_right" height="22"><a onclick="page_save()"><custom:button type="2" label="L_Save" imgsrc="save_btn.gif" border="0"/></a>
                              </td>
                            </tr>
                            <tr>
                              <%
                                boolean isReadonly;
                                String strClassType;
                                if (pageContext.getAttribute("cityinfo") != null && ((HashMap)pageContext.getAttribute("cityinfo")).get("cityid") != null) {
                                  isReadonly = true;
                                  strClassType = "td-text";
                                }
                                else {
                                  isReadonly = false;
                                  strClassType = "need";
                                }
                              %>
                              <td class="<%=JspHelper.filterNull( strClassType )%>" width="90"><%= label.getLabelName("L_CityCode") %><%= label.getLabelName("L_Colon") %></td>
                              <td width="250">
                                <custom:text name="cityinfo" property="citycode" size="20" command="notnull" module="OGM" label="L_CityCode" readonly="<%= isReadonly %>"/>
                              </td>
                              <td class="need" width="90"><%= label.getLabelName("L_CityName") %><%= label.getLabelName("L_Colon") %></td>
                              <td>
                                <custom:text name="cityinfo" property="cityname" size="20" command="notnull" module="OGM" label="L_CityName" needMLC="true" isFirstMLC="true" multiLangType="cityname" colIndex="0"/>
                                <custom:hidden name="cityinfo" property="cityname"/>
                                <a onclick='popup("../common/Lang.jsp?<%= OvalTools.randomURL() %>&form=frm&module=IMG&mlctype=L_CityName&nativelanguage=need&schema=ovcity1&qlname=selectbycode1&code=<custom:write name="cityinfo" property="citycode"/>&entitytype=cityname&contentid=cityid&colindex=0", "newwindow", "height=250, width=320,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no");'><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a>
                              </td>
                            </tr>
                            <tr>
                              <td class="need"><%= label.getLabelName("L_CountryName") %><%= label.getLabelName("L_Colon") %></td>
                              <!-- <td>
                                <custom:text name="cityinfo" property="countrycode" size="10" command="notnull" label="L_CountryCode"/>
                                <a onclick="javascript:page_selectCountry()"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                                <custom:text name="cityinfo" property="countryname" size="10" command="notnull" label="L_CountryName"/>
                              </td> -->
                              <td>
                                <custom:select name="cityinfo" property="countrycode" style="width:100" optionsName="allcountry" optionValueKey="countrycode" optionInnerTextKey="countryname" onchange="javascript:selectChange()"/>
                              </td>
                              <td class="need"><%= label.getLabelName("L_RegionName") %><%= label.getLabelName("L_Colon") %></td>
                              <td>
                                <custom:text name="cityinfo" property="regioncode" size="10" command="notnull" module="OGM" label="L_RegionCode" onchange="javascript:getRegion()"/>
                                <a onclick="javascript:page_selectRegion()"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                                <custom:text name="cityinfo" property="regionname" size="20" command="notnull" module="OGM" label="L_RegionName"/>
                              </td>
                            </tr>
                            <tr>
                              <td class="td-text"><%= label.getLabelName("L_ParentCity") %><%= label.getLabelName("L_Colon") %></td>
                              <custom:hidden property="parentcityid"></custom:hidden>
                              <td >
                                <custom:text name="cityinfo" property="parentcitycode" size="10" module="OGM" label="L_CityCode" onchange="javascript:getParentCity()" />
                                <a onclick="javascript:page_selectParentCity();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                                <custom:text name="cityinfo" property="parentcityname" size="20" module="OGM" label="L_CityName" changedName="parentcityname" />
                              </td>
                              <td class="td-text"><%= label.getLabelName("L_CostCenter") %><%= label.getLabelName("L_Colon") %></td>
                              <td>
                                <custom:text name="cityinfo" property="responsecode" size="10" module="OGM" label="L_CostCenterCode" />
                                <a onclick="javascript:page_selectCostCenter();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                                <custom:text name="cityinfo" property="responsename" size="20" module="OGM" label="L_CostCenterName" changedName="responsename" />
                                <custom:hidden name="cityinfo" property="responsecenterid" />
                            </td>
                            </tr>
                             <tr>
                              <td class="td-text"><%= label.getLabelName("L_WhetherArea") %><%= label.getLabelName("L_Colon") %></td>
                              <td colspan="3">
                                <custom:checkbox  property="istarget1"/>
                              </td>
                            </tr>
                            <tr>
                              <td class="td-text"><%= label.getLabelName("L_Spare1") %><%= label.getLabelName("L_Colon") %></td>
                              <td colspan="3">
                                <custom:text name="cityinfo" property="attr1" size="60"/>
                              </td>
                            </tr>
                            <tr>
                              <td class="td-text"><%= label.getLabelName("L_Spare2") %><%= label.getLabelName("L_Colon") %></td>
                              <td colspan="3">
                                <custom:text name="cityinfo" property="attr2" size="60"/>
                              </td>
                            </tr>
                            <tr>
                              <td class="td-text"><%= label.getLabelName("L_Spare3") %><%= label.getLabelName("L_Colon") %></td>
                              <td colspan="3">
                                <custom:text name="cityinfo" property="attr3" size="60"/>
                              </td>
                            </tr>
                            <tr>
                              <td class="td-text"><%= label.getLabelName("L_Spare4") %><%= label.getLabelName("L_Colon") %></td>
                              <td colspan="3">
                                <custom:text name="cityinfo" property="attr4" size="60"/>
                              </td>
                            </tr>
                          </table>
                        </div>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
              </tbody>
            </table>
          </td>
        </tr>
        <tr>
          <td class=summary_top></td>
        </tr>
        <tr>
          <td class=td_center><a onclick="self.location.href='CityCodeSummary.jsp'"><custom:button type="1" label="L_Back" imgsrc="finish.gif" border="0" style="width:60"/></a></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
<%
  Vector errorv = (Vector)session.getAttribute("errorcode");
  HashMap errorm = new HashMap();
  if(errorv != null && errorv.size() != 0) {
    errorm = (HashMap)errorv.get(0);
  }
  if(!errorm.isEmpty() && errorm.get("messagecode") != null) {
%>
<script>
  alert("<%= message.getMessageDesc(errorm) %>");
  frm.regioncode.value = "";
  frm.regionname.value = "";
</script>
<%
    session.removeAttribute("errorcode");
  }
%>
</html>
